package com.crionics.ghtable;

/* (swing1.1beta3)
 *example from 
 http://www.crionics.com/products/opensource/faq/swing_ex/SwingExamples.html 
 *
 */

/* (swing1.1beta3)
 *
 * |-----------------------------------------------------|
 * |        |       Name      |         Language         |
 * |        |-----------------|--------------------------|
 * |  SNo.  |        |        |        |      Others     |
 * |        |   1    |    2   | Native |-----------------|
 * |        |        |        |        |   2    |   3    |  
 * |-----------------------------------------------------|
 * |        |        |        |        |        |        |
 *
 */
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumnModel;

/**
 * @version 1.0 11/09/98
 */
@SuppressWarnings("serial")
public class GroupableHeaderExample extends JFrame {

	GroupableHeaderExample() {
		super("Groupable Header Example");

		DefaultTableModel dm = new DefaultTableModel();
		dm.setDataVector(new Object[][] {
				{ "119", "foo", "bar", "ja", "ko", "zh" },
				{ "911", "bar", "foo", "en", "fr", "pt" } }, new Object[] {
				"0", "1", "2", "3", "4", "5", "6", "7", "8",
				"9", "10", "11", "12", "13", "14", "15", "16"});

		JGHTable table = new JGHTable(dm);

		int c = 0;
		TableColumnModel cm = table.getColumnModel();
		ColumnGroup g_name = new ColumnGroup("Name");
		g_name.add(cm.getColumn(c++));
		g_name.add(cm.getColumn(c++));
		ColumnGroup g_lang = new ColumnGroup("Language");
		g_lang.add(cm.getColumn(c++));
		ColumnGroup g_other = new ColumnGroup("Others");
		g_other.add(cm.getColumn(c++));
		g_other.add(cm.getColumn(c++));
		g_lang.add(g_other);

		GroupableTableHeader header = table.getTableHeader();
		ColumnGroup g0 = new ColumnGroup("G0");
		g0.add(g_name);
		g0.add(g_lang);

		header.addColumnGroup(g0);
		
		c++;
		c++;
		
		g_name = new ColumnGroup("Name1");
		g_name.add(cm.getColumn(c));
		g_name.add(cm.getColumn(c++));
		
		g_lang = new ColumnGroup("Language1");
		g_lang.add(cm.getColumn(c++));
		g_other = new ColumnGroup("Others1");
		g_other.add(cm.getColumn(c++));
		g_other.add(cm.getColumn(c++));
		g_lang.add(g_other);
		
		
		
		ColumnGroup g1 = new ColumnGroup("G1");
		g1.add(g_name);
		g1.add(g_lang);

		header.addColumnGroup(g1);
		
		JScrollPane scroll = new JScrollPane(table);
		getContentPane().add(scroll);
		setSize(400, 120);
	}

	public static void main(String[] args) {
		GroupableHeaderExample frame = new GroupableHeaderExample();
		frame.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		});
		frame.setVisible(true);
	}
}